import Vue from 'vue'
import Router from 'vue-router'
import login from '@/components/login'
import myContentPage from '@/components/myContentPage'
import myTest from '@/components/myContent/myTest'
import testList from '@/components/myContent/testList'
import testResult from '@/components/myContent/testResult'
import subjectStoreroom from '@/components/myContent/subjectStoreroom'

Vue.use(Router)

var router=new Router({
  routes: [
    {
      path: '/login',
      name: 'login',
      component: login
    },
    {
      path: '/',
      name: 'myContentPage',
      component: myContentPage,
      redirect: '/myContentPage/subjectStoreroom',
     	children:[
	        { path: '/myContentPage/myTest',name:'myTest', component: myTest},
	        { path: '/myContentPage/testList',name:'testList', component: testList},
	        { path: '/myContentPage/testResult',name:'testResult', component: testResult},
	        { path: '/myContentPage/subjectStoreroom',name:'subjectStoreroom', component: subjectStoreroom}
	    ]
    }
  ]
})
router.beforeEach((to, from, next) => {
	if(to.name !== 'login'){
		if(localStorage.getItem('id')!=null){
			next();
		}else{
			next({
				name: 'login'
			});
		}
	}else{
		next();
	}
})
export default router